{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/Users/haithamelmarakeby/PycharmProjects/pnet2'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "import os\n",
    "from os.path import dirname, realpath, join\n",
    "base_dir = dirname(dirname(dirname(os.getcwd())))\n",
    "import itertools\n",
    "from mutex import MutEx\n",
    "import pandas as pd\n",
    "from os.path import join\n",
    "base_dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "sys.path.insert(0, base_dir)\n",
    "from config_path import PROSTATE_DATA_PATH, PLOTS_PATH\n",
    "from data.data_access import Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# interesting_genes = [('AR', 'cnv_amp'),\n",
    "# ('TP53', 'mut_important'),\n",
    "# ('MDM4', 'cnv_amp'),\n",
    "# ('CDK4', 'cnv_amp'),\n",
    "# ('CDK6', 'cnv_amp'),\n",
    "# ('CDKN2A', 'cnv_del'),\n",
    "# ('RB1', 'mut_important')]\n",
    "# pairs = list(itertools.combinations(interesting_genes, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "selected_genes = ['AR', 'TP53', 'MDM4', 'CDK4', 'CDK6', 'CDKN2A', 'RB1']\n",
    "data_params =  {'data_type': ['mut_important', 'cnv_del', 'cnv_amp'],\n",
    "                 'drop_AR': False,\n",
    "                 'cnv_levels': 5,\n",
    "                 'mut_binary': True,\n",
    "                 'balanced_data': False,\n",
    "                 'combine_type': 'union',  # intersection\n",
    "                 'use_coding_genes_only': False,\n",
    "                 'selected_genes': selected_genes}\n",
    "\n",
    "data_access_params= {'id': 'id', 'type': 'prostate_paper', 'params': data_params}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">TP53</th>\n",
       "      <th colspan=\"3\" halign=\"left\">CDK4</th>\n",
       "      <th colspan=\"3\" halign=\"left\">AR</th>\n",
       "      <th colspan=\"3\" halign=\"left\">RB1</th>\n",
       "      <th colspan=\"3\" halign=\"left\">CDKN2A</th>\n",
       "      <th colspan=\"3\" halign=\"left\">CDK6</th>\n",
       "      <th colspan=\"3\" halign=\"left\">MDM4</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>mut_important</th>\n",
       "      <th>cnv_del</th>\n",
       "      <th>cnv_amp</th>\n",
       "      <th>mut_important</th>\n",
       "      <th>cnv_del</th>\n",
       "      <th>cnv_amp</th>\n",
       "      <th>mut_important</th>\n",
       "      <th>cnv_del</th>\n",
       "      <th>cnv_amp</th>\n",
       "      <th>mut_important</th>\n",
       "      <th>...</th>\n",
       "      <th>cnv_amp</th>\n",
       "      <th>mut_important</th>\n",
       "      <th>cnv_del</th>\n",
       "      <th>cnv_amp</th>\n",
       "      <th>mut_important</th>\n",
       "      <th>cnv_del</th>\n",
       "      <th>cnv_amp</th>\n",
       "      <th>mut_important</th>\n",
       "      <th>cnv_del</th>\n",
       "      <th>cnv_amp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>00-029N9_LN</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>01-087MM_BONE</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>01-095N1_LN</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>01-120A1_LIVER</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>02-083E1_LN</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        TP53                          CDK4                  \\\n",
       "               mut_important cnv_del cnv_amp mut_important cnv_del cnv_amp   \n",
       "00-029N9_LN              0.0     0.5     0.0           0.0     0.0     0.0   \n",
       "01-087MM_BONE            0.0     0.0     0.0           0.0     0.0     0.5   \n",
       "01-095N1_LN              0.0     0.5     0.0           0.0     0.0     0.0   \n",
       "01-120A1_LIVER           0.0     0.5     0.0           0.0     0.0     0.0   \n",
       "02-083E1_LN              0.0     0.0     0.0           0.0     0.0     0.0   \n",
       "\n",
       "                          AR                           RB1  ...          \\\n",
       "               mut_important cnv_del cnv_amp mut_important  ... cnv_amp   \n",
       "00-029N9_LN              0.0     0.0     0.0           0.0  ...     0.0   \n",
       "01-087MM_BONE            1.0     0.0     0.0           0.0  ...     0.0   \n",
       "01-095N1_LN              0.0     0.0     0.0           0.0  ...     0.0   \n",
       "01-120A1_LIVER           0.0     0.0     0.0           0.0  ...     0.0   \n",
       "02-083E1_LN              0.0     0.0     0.5           0.0  ...     0.0   \n",
       "\n",
       "                      CDKN2A                          CDK6                  \\\n",
       "               mut_important cnv_del cnv_amp mut_important cnv_del cnv_amp   \n",
       "00-029N9_LN              0.0     0.0     0.0           0.0     0.0     0.0   \n",
       "01-087MM_BONE            0.0     0.0     0.0           0.0     0.0     0.0   \n",
       "01-095N1_LN              0.0     0.0     0.0           0.0     0.0     0.0   \n",
       "01-120A1_LIVER           0.0     0.0     0.0           0.0     0.0     0.0   \n",
       "02-083E1_LN              0.0     0.0     0.0           0.0     0.0     0.0   \n",
       "\n",
       "                        MDM4                  \n",
       "               mut_important cnv_del cnv_amp  \n",
       "00-029N9_LN              0.0     0.0     0.0  \n",
       "01-087MM_BONE            0.0     0.0     0.0  \n",
       "01-095N1_LN              0.0     0.0     0.0  \n",
       "01-120A1_LIVER           0.0     0.0     0.0  \n",
       "02-083E1_LN              0.0     0.0     0.5  \n",
       "\n",
       "[5 rows x 21 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_adapter = Data(**data_access_params)\n",
    "x, y, info, columns = data_adapter.get_data()\n",
    "x_df = pd.DataFrame(x, columns= columns, index= info)\n",
    "x_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#include single copy amp and delete\n",
    "# x_df_5= x_df.copy()\n",
    "# x_df_5[x_df_5>0] = 1\n",
    "# x_df_5.shape\n",
    "\n",
    "# high amp and deep del\n",
    "# x_df_3= x_df.copy()\n",
    "# x_df_3[x_df_3<1] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(7, 1011)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_df_5 = x_df.T.reset_index().groupby('level_0').sum()\n",
    "x_df_5[x_df_5>0] = 1\n",
    "x_df_5.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(7, 1011)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_df_3= x_df.copy()\n",
    "x_df_3[x_df_3<1] = 0 #remove single copy\n",
    "\n",
    "x_df_3 = x_df_3.T.reset_index().groupby('level_0').sum() # all events (OR)\n",
    "x_df_3[x_df_3>0] = 1 # binarize \n",
    "x_df_3.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_ind = y>0\n",
    "x_df_mets_3 = x_df_3.T[y_ind].T\n",
    "x_df_mets_5 = x_df_5.T[y_ind].T\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "selected_genes = ['AR', 'TP53', 'MDM4', 'CDK4', 'CDK6', 'CDKN2A', 'RB1']\n",
    "pairs = list(itertools.combinations(selected_genes, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>00-029N9_LN</th>\n",
       "      <th>01-087MM_BONE</th>\n",
       "      <th>01-095N1_LN</th>\n",
       "      <th>01-120A1_LIVER</th>\n",
       "      <th>02-083E1_LN</th>\n",
       "      <th>03-082H1_LIVER</th>\n",
       "      <th>03-130L_RETROPERITONEAL</th>\n",
       "      <th>03-139E3_RETROPERITONEAL</th>\n",
       "      <th>03-163S4_LIVER</th>\n",
       "      <th>03-192B_LUNG</th>\n",
       "      <th>...</th>\n",
       "      <th>TP_2032</th>\n",
       "      <th>TP_2034</th>\n",
       "      <th>TP_2054</th>\n",
       "      <th>TP_2060</th>\n",
       "      <th>TP_2061</th>\n",
       "      <th>TP_2064</th>\n",
       "      <th>TP_2069</th>\n",
       "      <th>TP_2077</th>\n",
       "      <th>TP_2078</th>\n",
       "      <th>TP_2079</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>level_0</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AR</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK6</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDKN2A</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MDM4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 1011 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         00-029N9_LN  01-087MM_BONE  01-095N1_LN  01-120A1_LIVER  02-083E1_LN  \\\n",
       "level_0                                                                         \n",
       "AR               0.0            1.0          0.0             0.0          0.0   \n",
       "CDK4             0.0            0.0          0.0             0.0          0.0   \n",
       "CDK6             0.0            0.0          0.0             0.0          0.0   \n",
       "CDKN2A           0.0            0.0          0.0             0.0          0.0   \n",
       "MDM4             0.0            0.0          0.0             0.0          0.0   \n",
       "\n",
       "         03-082H1_LIVER  03-130L_RETROPERITONEAL  03-139E3_RETROPERITONEAL  \\\n",
       "level_0                                                                      \n",
       "AR                  1.0                      0.0                       0.0   \n",
       "CDK4                0.0                      0.0                       0.0   \n",
       "CDK6                0.0                      0.0                       0.0   \n",
       "CDKN2A              0.0                      0.0                       0.0   \n",
       "MDM4                0.0                      0.0                       0.0   \n",
       "\n",
       "         03-163S4_LIVER  03-192B_LUNG  ...  TP_2032  TP_2034  TP_2054  \\\n",
       "level_0                                ...                              \n",
       "AR                  0.0           0.0  ...      1.0      1.0      0.0   \n",
       "CDK4                0.0           0.0  ...      0.0      0.0      0.0   \n",
       "CDK6                0.0           0.0  ...      0.0      0.0      0.0   \n",
       "CDKN2A              0.0           0.0  ...      0.0      0.0      0.0   \n",
       "MDM4                0.0           0.0  ...      0.0      0.0      0.0   \n",
       "\n",
       "         TP_2060  TP_2061  TP_2064  TP_2069  TP_2077  TP_2078  TP_2079  \n",
       "level_0                                                                 \n",
       "AR           1.0      1.0      1.0      0.0      0.0      0.0      1.0  \n",
       "CDK4         0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDK6         0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDKN2A       0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "MDM4         0.0      0.0      1.0      0.0      0.0      0.0      0.0  \n",
       "\n",
       "[5 rows x 1011 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_df_3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0    844\n",
       "1.0    167\n",
       "Name: AR, dtype: int64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_df_3.T.AR.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Mutex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "random.seed(18)\n",
    "\n",
    "def run_mutex(x_df, pairs, permutations =2000, saving_file='mutex' ):\n",
    "    results=[]\n",
    "#     df = x_df.copy()\n",
    "#     df = df.T\n",
    "    df=x_df.astype(int)\n",
    "    m = MutEx(background=df, permutations=permutations)\n",
    "    for g1, g2 in pairs:\n",
    "        print (g1)\n",
    "        print (g2)\n",
    "        r = m.calculate([g1, g2], parallel=True)\n",
    "        print (r.mutex_pvalue, r.co_occurence_pvalue)\n",
    "        results.append(r)\n",
    "    \n",
    "    results_dict_list=[]\n",
    "    for r in results:\n",
    "        g1, g2 = r.items\n",
    "        results_dict={}\n",
    "        results_dict['g1'] = g1\n",
    "        results_dict['g2'] = g2\n",
    "        results_dict['mutex_pvalue'] = r.mutex_pvalue\n",
    "        results_dict['co_occurence_pvalue'] = r.co_occurence_pvalue\n",
    "        results_dict['zscore'] = r.zscore\n",
    "        results_dict['signal'] = r.signal\n",
    "        results_dict['coverage'] = r.coverage\n",
    "        results_dict['signal_coverage_ratio'] = r.signal_coverage_ratio\n",
    "        results_dict_list.append(results_dict)\n",
    "    results_df = pd.DataFrame(results_dict_list)\n",
    "    cols= ['g1', 'g2', 'mutex_pvalue', 'co_occurence_pvalue', 'zscore', 'signal', 'coverage', 'signal_coverage_ratio']\n",
    "    results_df = results_df.reindex(cols, axis=1)\n",
    "    results_df.to_csv('{}.csv'.format(saving_file))\n",
    "    return results_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>00-029N9_LN</th>\n",
       "      <th>01-087MM_BONE</th>\n",
       "      <th>01-095N1_LN</th>\n",
       "      <th>01-120A1_LIVER</th>\n",
       "      <th>02-083E1_LN</th>\n",
       "      <th>03-082H1_LIVER</th>\n",
       "      <th>03-130L_RETROPERITONEAL</th>\n",
       "      <th>03-139E3_RETROPERITONEAL</th>\n",
       "      <th>03-163S4_LIVER</th>\n",
       "      <th>03-192B_LUNG</th>\n",
       "      <th>...</th>\n",
       "      <th>TP_2032</th>\n",
       "      <th>TP_2034</th>\n",
       "      <th>TP_2054</th>\n",
       "      <th>TP_2060</th>\n",
       "      <th>TP_2061</th>\n",
       "      <th>TP_2064</th>\n",
       "      <th>TP_2069</th>\n",
       "      <th>TP_2077</th>\n",
       "      <th>TP_2078</th>\n",
       "      <th>TP_2079</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>level_0</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AR</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK6</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDKN2A</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MDM4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 1011 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         00-029N9_LN  01-087MM_BONE  01-095N1_LN  01-120A1_LIVER  02-083E1_LN  \\\n",
       "level_0                                                                         \n",
       "AR               0.0            1.0          0.0             0.0          1.0   \n",
       "CDK4             0.0            1.0          0.0             0.0          0.0   \n",
       "CDK6             0.0            0.0          0.0             0.0          0.0   \n",
       "CDKN2A           0.0            0.0          0.0             0.0          0.0   \n",
       "MDM4             0.0            0.0          0.0             0.0          1.0   \n",
       "\n",
       "         03-082H1_LIVER  03-130L_RETROPERITONEAL  03-139E3_RETROPERITONEAL  \\\n",
       "level_0                                                                      \n",
       "AR                  1.0                      0.0                       0.0   \n",
       "CDK4                0.0                      0.0                       0.0   \n",
       "CDK6                0.0                      0.0                       0.0   \n",
       "CDKN2A              0.0                      0.0                       0.0   \n",
       "MDM4                0.0                      1.0                       0.0   \n",
       "\n",
       "         03-163S4_LIVER  03-192B_LUNG  ...  TP_2032  TP_2034  TP_2054  \\\n",
       "level_0                                ...                              \n",
       "AR                  0.0           0.0  ...      1.0      1.0      0.0   \n",
       "CDK4                0.0           0.0  ...      0.0      0.0      0.0   \n",
       "CDK6                0.0           0.0  ...      0.0      0.0      1.0   \n",
       "CDKN2A              0.0           1.0  ...      0.0      0.0      0.0   \n",
       "MDM4                0.0           0.0  ...      0.0      0.0      1.0   \n",
       "\n",
       "         TP_2060  TP_2061  TP_2064  TP_2069  TP_2077  TP_2078  TP_2079  \n",
       "level_0                                                                 \n",
       "AR           1.0      1.0      1.0      1.0      0.0      0.0      1.0  \n",
       "CDK4         0.0      0.0      0.0      0.0      0.0      1.0      0.0  \n",
       "CDK6         0.0      0.0      0.0      1.0      0.0      0.0      1.0  \n",
       "CDKN2A       0.0      1.0      0.0      1.0      0.0      0.0      0.0  \n",
       "MDM4         0.0      1.0      1.0      0.0      0.0      1.0      0.0  \n",
       "\n",
       "[5 rows x 1011 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_df_5.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR\n",
      "TP53\n",
      "0.9645 0.0355\n",
      "AR\n",
      "MDM4\n",
      "1.0 0.0\n",
      "AR\n",
      "CDK4\n",
      "1.0 0.0\n",
      "AR\n",
      "CDK6\n",
      "0.982 0.0235\n",
      "AR\n",
      "CDKN2A\n",
      "0.9885 0.0175\n",
      "AR\n",
      "RB1\n",
      "0.0715 0.9405\n",
      "TP53\n",
      "MDM4\n",
      "0.161 0.869\n",
      "TP53\n",
      "CDK4\n",
      "0.1435 0.928\n",
      "TP53\n",
      "CDK6\n",
      "0.006 0.994\n",
      "TP53\n",
      "CDKN2A\n",
      "1.0 0.0\n",
      "TP53\n",
      "RB1\n",
      "0.0 1.0\n",
      "MDM4\n",
      "CDK4\n",
      "1.0 0.0\n",
      "MDM4\n",
      "CDK6\n",
      "1.0 0.0\n",
      "MDM4\n",
      "CDKN2A\n",
      "0.976 0.0295\n",
      "MDM4\n",
      "RB1\n",
      "0.16 0.8755\n",
      "CDK4\n",
      "CDK6\n",
      "0.4775 0.642\n",
      "CDK4\n",
      "CDKN2A\n",
      "0.7015 0.3935\n",
      "CDK4\n",
      "RB1\n",
      "0.0 1.0\n",
      "CDK6\n",
      "CDKN2A\n",
      "0.845 0.2325\n",
      "CDK6\n",
      "RB1\n",
      "0.0 1.0\n",
      "CDKN2A\n",
      "RB1\n",
      "0.1855 0.862\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>g1</th>\n",
       "      <th>g2</th>\n",
       "      <th>mutex_pvalue</th>\n",
       "      <th>co_occurence_pvalue</th>\n",
       "      <th>zscore</th>\n",
       "      <th>signal</th>\n",
       "      <th>coverage</th>\n",
       "      <th>signal_coverage_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AR</td>\n",
       "      <td>TP53</td>\n",
       "      <td>0.9645</td>\n",
       "      <td>0.0355</td>\n",
       "      <td>-1.750681</td>\n",
       "      <td>690</td>\n",
       "      <td>539</td>\n",
       "      <td>0.781159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AR</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-5.893732</td>\n",
       "      <td>399</td>\n",
       "      <td>305</td>\n",
       "      <td>0.764411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-3.998779</td>\n",
       "      <td>338</td>\n",
       "      <td>276</td>\n",
       "      <td>0.816568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.9820</td>\n",
       "      <td>0.0235</td>\n",
       "      <td>-1.961861</td>\n",
       "      <td>475</td>\n",
       "      <td>380</td>\n",
       "      <td>0.800000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.9885</td>\n",
       "      <td>0.0175</td>\n",
       "      <td>-2.269935</td>\n",
       "      <td>337</td>\n",
       "      <td>284</td>\n",
       "      <td>0.842730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>AR</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0715</td>\n",
       "      <td>0.9405</td>\n",
       "      <td>1.484890</td>\n",
       "      <td>772</td>\n",
       "      <td>619</td>\n",
       "      <td>0.801813</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>TP53</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.1610</td>\n",
       "      <td>0.8690</td>\n",
       "      <td>1.137128</td>\n",
       "      <td>695</td>\n",
       "      <td>557</td>\n",
       "      <td>0.801439</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.1435</td>\n",
       "      <td>0.9280</td>\n",
       "      <td>1.265410</td>\n",
       "      <td>634</td>\n",
       "      <td>539</td>\n",
       "      <td>0.850158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.0060</td>\n",
       "      <td>0.9940</td>\n",
       "      <td>2.475025</td>\n",
       "      <td>771</td>\n",
       "      <td>591</td>\n",
       "      <td>0.766537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-3.931258</td>\n",
       "      <td>633</td>\n",
       "      <td>514</td>\n",
       "      <td>0.812006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>TP53</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>5.394251</td>\n",
       "      <td>1068</td>\n",
       "      <td>723</td>\n",
       "      <td>0.676966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-4.344746</td>\n",
       "      <td>343</td>\n",
       "      <td>277</td>\n",
       "      <td>0.807580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-3.438148</td>\n",
       "      <td>480</td>\n",
       "      <td>372</td>\n",
       "      <td>0.775000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.9760</td>\n",
       "      <td>0.0295</td>\n",
       "      <td>-2.210530</td>\n",
       "      <td>342</td>\n",
       "      <td>287</td>\n",
       "      <td>0.839181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.1600</td>\n",
       "      <td>0.8755</td>\n",
       "      <td>1.098343</td>\n",
       "      <td>777</td>\n",
       "      <td>619</td>\n",
       "      <td>0.796654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.4775</td>\n",
       "      <td>0.6420</td>\n",
       "      <td>0.210228</td>\n",
       "      <td>419</td>\n",
       "      <td>360</td>\n",
       "      <td>0.859189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.7015</td>\n",
       "      <td>0.3935</td>\n",
       "      <td>-0.369974</td>\n",
       "      <td>281</td>\n",
       "      <td>248</td>\n",
       "      <td>0.882562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.740292</td>\n",
       "      <td>716</td>\n",
       "      <td>619</td>\n",
       "      <td>0.864525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.8450</td>\n",
       "      <td>0.2325</td>\n",
       "      <td>-0.880499</td>\n",
       "      <td>418</td>\n",
       "      <td>353</td>\n",
       "      <td>0.844498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>2.838496</td>\n",
       "      <td>853</td>\n",
       "      <td>644</td>\n",
       "      <td>0.754982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.1855</td>\n",
       "      <td>0.8620</td>\n",
       "      <td>0.930911</td>\n",
       "      <td>715</td>\n",
       "      <td>605</td>\n",
       "      <td>0.846154</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        g1      g2  mutex_pvalue  co_occurence_pvalue    zscore  signal  \\\n",
       "0       AR    TP53        0.9645               0.0355 -1.750681     690   \n",
       "1       AR    MDM4        1.0000               0.0000 -5.893732     399   \n",
       "2       AR    CDK4        1.0000               0.0000 -3.998779     338   \n",
       "3       AR    CDK6        0.9820               0.0235 -1.961861     475   \n",
       "4       AR  CDKN2A        0.9885               0.0175 -2.269935     337   \n",
       "5       AR     RB1        0.0715               0.9405  1.484890     772   \n",
       "6     TP53    MDM4        0.1610               0.8690  1.137128     695   \n",
       "7     TP53    CDK4        0.1435               0.9280  1.265410     634   \n",
       "8     TP53    CDK6        0.0060               0.9940  2.475025     771   \n",
       "9     TP53  CDKN2A        1.0000               0.0000 -3.931258     633   \n",
       "10    TP53     RB1        0.0000               1.0000  5.394251    1068   \n",
       "11    MDM4    CDK4        1.0000               0.0000 -4.344746     343   \n",
       "12    MDM4    CDK6        1.0000               0.0000 -3.438148     480   \n",
       "13    MDM4  CDKN2A        0.9760               0.0295 -2.210530     342   \n",
       "14    MDM4     RB1        0.1600               0.8755  1.098343     777   \n",
       "15    CDK4    CDK6        0.4775               0.6420  0.210228     419   \n",
       "16    CDK4  CDKN2A        0.7015               0.3935 -0.369974     281   \n",
       "17    CDK4     RB1        0.0000               1.0000  3.740292     716   \n",
       "18    CDK6  CDKN2A        0.8450               0.2325 -0.880499     418   \n",
       "19    CDK6     RB1        0.0000               1.0000  2.838496     853   \n",
       "20  CDKN2A     RB1        0.1855               0.8620  0.930911     715   \n",
       "\n",
       "    coverage  signal_coverage_ratio  \n",
       "0        539               0.781159  \n",
       "1        305               0.764411  \n",
       "2        276               0.816568  \n",
       "3        380               0.800000  \n",
       "4        284               0.842730  \n",
       "5        619               0.801813  \n",
       "6        557               0.801439  \n",
       "7        539               0.850158  \n",
       "8        591               0.766537  \n",
       "9        514               0.812006  \n",
       "10       723               0.676966  \n",
       "11       277               0.807580  \n",
       "12       372               0.775000  \n",
       "13       287               0.839181  \n",
       "14       619               0.796654  \n",
       "15       360               0.859189  \n",
       "16       248               0.882562  \n",
       "17       619               0.864525  \n",
       "18       353               0.844498  \n",
       "19       644               0.754982  \n",
       "20       605               0.846154  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_mutex(x_df_5, pairs, permutations=2000,saving_file ='mutex_all_cnv_5' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR\n",
      "TP53\n",
      "0.0 1.0\n",
      "AR\n",
      "MDM4\n",
      "0.156 0.928\n",
      "AR\n",
      "CDK4\n",
      "0.2795 0.881\n",
      "AR\n",
      "CDK6\n",
      "0.0 1.0\n",
      "AR\n",
      "CDKN2A\n",
      "0.0 1.0\n",
      "AR\n",
      "RB1\n",
      "0.0 1.0\n",
      "TP53\n",
      "MDM4\n",
      "0.0 1.0\n",
      "TP53\n",
      "CDK4\n",
      "0.006 1.0\n",
      "TP53\n",
      "CDK6\n",
      "0.0 1.0\n",
      "TP53\n",
      "CDKN2A\n",
      "0.0 1.0\n",
      "TP53\n",
      "RB1\n",
      "0.042 0.976\n",
      "MDM4\n",
      "CDK4\n",
      "1.0 0.0\n",
      "MDM4\n",
      "CDK6\n",
      "0.5475 0.72\n",
      "MDM4\n",
      "CDKN2A\n",
      "0.47 0.839\n",
      "MDM4\n",
      "RB1\n",
      "0.131 0.9645\n",
      "CDK4\n",
      "CDK6\n",
      "0.774 0.4045\n",
      "CDK4\n",
      "CDKN2A\n",
      "0.2965 1.0\n",
      "CDK4\n",
      "RB1\n",
      "0.0595 0.9885\n",
      "CDK6\n",
      "CDKN2A\n",
      "0.2265 1.0\n",
      "CDK6\n",
      "RB1\n",
      "0.0 1.0\n",
      "CDKN2A\n",
      "RB1\n",
      "0.2315 0.9405\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>g1</th>\n",
       "      <th>g2</th>\n",
       "      <th>mutex_pvalue</th>\n",
       "      <th>co_occurence_pvalue</th>\n",
       "      <th>zscore</th>\n",
       "      <th>signal</th>\n",
       "      <th>coverage</th>\n",
       "      <th>signal_coverage_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AR</td>\n",
       "      <td>TP53</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>7.000722</td>\n",
       "      <td>375</td>\n",
       "      <td>315</td>\n",
       "      <td>0.840000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AR</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.1560</td>\n",
       "      <td>0.9280</td>\n",
       "      <td>1.292803</td>\n",
       "      <td>204</td>\n",
       "      <td>190</td>\n",
       "      <td>0.931373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.2795</td>\n",
       "      <td>0.8810</td>\n",
       "      <td>0.740502</td>\n",
       "      <td>190</td>\n",
       "      <td>181</td>\n",
       "      <td>0.952632</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.232258</td>\n",
       "      <td>198</td>\n",
       "      <td>191</td>\n",
       "      <td>0.964646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>2.583596</td>\n",
       "      <td>183</td>\n",
       "      <td>180</td>\n",
       "      <td>0.983607</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>AR</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>4.204918</td>\n",
       "      <td>223</td>\n",
       "      <td>210</td>\n",
       "      <td>0.941704</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>TP53</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>4.986098</td>\n",
       "      <td>245</td>\n",
       "      <td>237</td>\n",
       "      <td>0.967347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.0060</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.178498</td>\n",
       "      <td>231</td>\n",
       "      <td>225</td>\n",
       "      <td>0.974026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>5.082680</td>\n",
       "      <td>239</td>\n",
       "      <td>234</td>\n",
       "      <td>0.979079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.399513</td>\n",
       "      <td>224</td>\n",
       "      <td>221</td>\n",
       "      <td>0.986607</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>TP53</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0420</td>\n",
       "      <td>0.9760</td>\n",
       "      <td>1.739183</td>\n",
       "      <td>264</td>\n",
       "      <td>237</td>\n",
       "      <td>0.897727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-3.281882</td>\n",
       "      <td>60</td>\n",
       "      <td>53</td>\n",
       "      <td>0.883333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.5475</td>\n",
       "      <td>0.7200</td>\n",
       "      <td>0.351535</td>\n",
       "      <td>68</td>\n",
       "      <td>65</td>\n",
       "      <td>0.955882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.4700</td>\n",
       "      <td>0.8390</td>\n",
       "      <td>0.604290</td>\n",
       "      <td>53</td>\n",
       "      <td>52</td>\n",
       "      <td>0.981132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.1310</td>\n",
       "      <td>0.9645</td>\n",
       "      <td>1.443357</td>\n",
       "      <td>93</td>\n",
       "      <td>90</td>\n",
       "      <td>0.967742</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.7740</td>\n",
       "      <td>0.4045</td>\n",
       "      <td>-0.450578</td>\n",
       "      <td>54</td>\n",
       "      <td>51</td>\n",
       "      <td>0.944444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.2965</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>1.171448</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0595</td>\n",
       "      <td>0.9885</td>\n",
       "      <td>1.639864</td>\n",
       "      <td>79</td>\n",
       "      <td>78</td>\n",
       "      <td>0.987342</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.2265</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>1.260089</td>\n",
       "      <td>47</td>\n",
       "      <td>47</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>2.472800</td>\n",
       "      <td>87</td>\n",
       "      <td>87</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.2315</td>\n",
       "      <td>0.9405</td>\n",
       "      <td>1.072148</td>\n",
       "      <td>72</td>\n",
       "      <td>71</td>\n",
       "      <td>0.986111</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        g1      g2  mutex_pvalue  co_occurence_pvalue    zscore  signal  \\\n",
       "0       AR    TP53        0.0000               1.0000  7.000722     375   \n",
       "1       AR    MDM4        0.1560               0.9280  1.292803     204   \n",
       "2       AR    CDK4        0.2795               0.8810  0.740502     190   \n",
       "3       AR    CDK6        0.0000               1.0000  3.232258     198   \n",
       "4       AR  CDKN2A        0.0000               1.0000  2.583596     183   \n",
       "5       AR     RB1        0.0000               1.0000  4.204918     223   \n",
       "6     TP53    MDM4        0.0000               1.0000  4.986098     245   \n",
       "7     TP53    CDK4        0.0060               1.0000  3.178498     231   \n",
       "8     TP53    CDK6        0.0000               1.0000  5.082680     239   \n",
       "9     TP53  CDKN2A        0.0000               1.0000  3.399513     224   \n",
       "10    TP53     RB1        0.0420               0.9760  1.739183     264   \n",
       "11    MDM4    CDK4        1.0000               0.0000 -3.281882      60   \n",
       "12    MDM4    CDK6        0.5475               0.7200  0.351535      68   \n",
       "13    MDM4  CDKN2A        0.4700               0.8390  0.604290      53   \n",
       "14    MDM4     RB1        0.1310               0.9645  1.443357      93   \n",
       "15    CDK4    CDK6        0.7740               0.4045 -0.450578      54   \n",
       "16    CDK4  CDKN2A        0.2965               1.0000  1.171448      39   \n",
       "17    CDK4     RB1        0.0595               0.9885  1.639864      79   \n",
       "18    CDK6  CDKN2A        0.2265               1.0000  1.260089      47   \n",
       "19    CDK6     RB1        0.0000               1.0000  2.472800      87   \n",
       "20  CDKN2A     RB1        0.2315               0.9405  1.072148      72   \n",
       "\n",
       "    coverage  signal_coverage_ratio  \n",
       "0        315               0.840000  \n",
       "1        190               0.931373  \n",
       "2        181               0.952632  \n",
       "3        191               0.964646  \n",
       "4        180               0.983607  \n",
       "5        210               0.941704  \n",
       "6        237               0.967347  \n",
       "7        225               0.974026  \n",
       "8        234               0.979079  \n",
       "9        221               0.986607  \n",
       "10       237               0.897727  \n",
       "11        53               0.883333  \n",
       "12        65               0.955882  \n",
       "13        52               0.981132  \n",
       "14        90               0.967742  \n",
       "15        51               0.944444  \n",
       "16        39               1.000000  \n",
       "17        78               0.987342  \n",
       "18        47               1.000000  \n",
       "19        87               1.000000  \n",
       "20        71               0.986111  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_mutex(x_df_3, pairs, permutations=2000,saving_file ='mutex_all_cnv_3' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR\n",
      "TP53\n",
      "0.0 1.0\n",
      "AR\n",
      "MDM4\n",
      "0.0475 0.9825\n",
      "AR\n",
      "CDK4\n",
      "0.488 0.7625\n",
      "AR\n",
      "CDK6\n",
      "0.0655 0.976\n",
      "AR\n",
      "CDKN2A\n",
      "0.0175 0.9945\n",
      "AR\n",
      "RB1\n",
      "0.0 1.0\n",
      "TP53\n",
      "MDM4\n",
      "0.006 0.994\n",
      "TP53\n",
      "CDK4\n",
      "0.095 0.982\n",
      "TP53\n",
      "CDK6\n",
      "0.024 1.0\n",
      "TP53\n",
      "CDKN2A\n",
      "0.006 0.994\n",
      "TP53\n",
      "RB1\n",
      "0.686 0.4515\n",
      "MDM4\n",
      "CDK4\n",
      "1.0 0.012\n",
      "MDM4\n",
      "CDK6\n",
      "0.786 0.548\n",
      "MDM4\n",
      "CDKN2A\n",
      "0.651 0.712\n",
      "MDM4\n",
      "RB1\n",
      "0.3695 0.8385\n",
      "CDK4\n",
      "CDK6\n",
      "0.851 0.5525\n",
      "CDK4\n",
      "CDKN2A\n",
      "0.5615 1.0\n",
      "CDK4\n",
      "RB1\n",
      "0.315 0.917\n",
      "CDK6\n",
      "CDKN2A\n",
      "0.459 1.0\n",
      "CDK6\n",
      "RB1\n",
      "0.054 1.0\n",
      "CDKN2A\n",
      "RB1\n",
      "0.4515 0.899\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>g1</th>\n",
       "      <th>g2</th>\n",
       "      <th>mutex_pvalue</th>\n",
       "      <th>co_occurence_pvalue</th>\n",
       "      <th>zscore</th>\n",
       "      <th>signal</th>\n",
       "      <th>coverage</th>\n",
       "      <th>signal_coverage_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AR</td>\n",
       "      <td>TP53</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>6.416440</td>\n",
       "      <td>283</td>\n",
       "      <td>225</td>\n",
       "      <td>0.795053</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AR</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.0475</td>\n",
       "      <td>0.9825</td>\n",
       "      <td>1.861460</td>\n",
       "      <td>185</td>\n",
       "      <td>172</td>\n",
       "      <td>0.929730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.4880</td>\n",
       "      <td>0.7625</td>\n",
       "      <td>0.237641</td>\n",
       "      <td>172</td>\n",
       "      <td>164</td>\n",
       "      <td>0.953488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.0655</td>\n",
       "      <td>0.9760</td>\n",
       "      <td>1.914035</td>\n",
       "      <td>175</td>\n",
       "      <td>168</td>\n",
       "      <td>0.960000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.0175</td>\n",
       "      <td>0.9945</td>\n",
       "      <td>2.633663</td>\n",
       "      <td>170</td>\n",
       "      <td>167</td>\n",
       "      <td>0.982353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>AR</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>4.663097</td>\n",
       "      <td>197</td>\n",
       "      <td>184</td>\n",
       "      <td>0.934010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>TP53</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.0060</td>\n",
       "      <td>0.9940</td>\n",
       "      <td>3.088400</td>\n",
       "      <td>148</td>\n",
       "      <td>141</td>\n",
       "      <td>0.952703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.0950</td>\n",
       "      <td>0.9820</td>\n",
       "      <td>1.573393</td>\n",
       "      <td>135</td>\n",
       "      <td>131</td>\n",
       "      <td>0.970370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.0240</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>2.252810</td>\n",
       "      <td>138</td>\n",
       "      <td>134</td>\n",
       "      <td>0.971014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.0060</td>\n",
       "      <td>0.9940</td>\n",
       "      <td>2.390519</td>\n",
       "      <td>133</td>\n",
       "      <td>131</td>\n",
       "      <td>0.984962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>TP53</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.6860</td>\n",
       "      <td>0.4515</td>\n",
       "      <td>-0.275276</td>\n",
       "      <td>160</td>\n",
       "      <td>139</td>\n",
       "      <td>0.868750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0120</td>\n",
       "      <td>-3.112409</td>\n",
       "      <td>37</td>\n",
       "      <td>32</td>\n",
       "      <td>0.864865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.7860</td>\n",
       "      <td>0.5480</td>\n",
       "      <td>-0.234374</td>\n",
       "      <td>40</td>\n",
       "      <td>38</td>\n",
       "      <td>0.950000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.6510</td>\n",
       "      <td>0.7120</td>\n",
       "      <td>0.209752</td>\n",
       "      <td>35</td>\n",
       "      <td>34</td>\n",
       "      <td>0.971429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.3695</td>\n",
       "      <td>0.8385</td>\n",
       "      <td>0.638155</td>\n",
       "      <td>62</td>\n",
       "      <td>59</td>\n",
       "      <td>0.951613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.8510</td>\n",
       "      <td>0.5525</td>\n",
       "      <td>-0.313667</td>\n",
       "      <td>27</td>\n",
       "      <td>26</td>\n",
       "      <td>0.962963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.5615</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.784154</td>\n",
       "      <td>22</td>\n",
       "      <td>22</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.3150</td>\n",
       "      <td>0.9170</td>\n",
       "      <td>0.923824</td>\n",
       "      <td>49</td>\n",
       "      <td>48</td>\n",
       "      <td>0.979592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.4590</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.873585</td>\n",
       "      <td>25</td>\n",
       "      <td>25</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0540</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>1.665350</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.4515</td>\n",
       "      <td>0.8990</td>\n",
       "      <td>0.678189</td>\n",
       "      <td>47</td>\n",
       "      <td>46</td>\n",
       "      <td>0.978723</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        g1      g2  mutex_pvalue  co_occurence_pvalue    zscore  signal  \\\n",
       "0       AR    TP53        0.0000               1.0000  6.416440     283   \n",
       "1       AR    MDM4        0.0475               0.9825  1.861460     185   \n",
       "2       AR    CDK4        0.4880               0.7625  0.237641     172   \n",
       "3       AR    CDK6        0.0655               0.9760  1.914035     175   \n",
       "4       AR  CDKN2A        0.0175               0.9945  2.633663     170   \n",
       "5       AR     RB1        0.0000               1.0000  4.663097     197   \n",
       "6     TP53    MDM4        0.0060               0.9940  3.088400     148   \n",
       "7     TP53    CDK4        0.0950               0.9820  1.573393     135   \n",
       "8     TP53    CDK6        0.0240               1.0000  2.252810     138   \n",
       "9     TP53  CDKN2A        0.0060               0.9940  2.390519     133   \n",
       "10    TP53     RB1        0.6860               0.4515 -0.275276     160   \n",
       "11    MDM4    CDK4        1.0000               0.0120 -3.112409      37   \n",
       "12    MDM4    CDK6        0.7860               0.5480 -0.234374      40   \n",
       "13    MDM4  CDKN2A        0.6510               0.7120  0.209752      35   \n",
       "14    MDM4     RB1        0.3695               0.8385  0.638155      62   \n",
       "15    CDK4    CDK6        0.8510               0.5525 -0.313667      27   \n",
       "16    CDK4  CDKN2A        0.5615               1.0000  0.784154      22   \n",
       "17    CDK4     RB1        0.3150               0.9170  0.923824      49   \n",
       "18    CDK6  CDKN2A        0.4590               1.0000  0.873585      25   \n",
       "19    CDK6     RB1        0.0540               1.0000  1.665350      52   \n",
       "20  CDKN2A     RB1        0.4515               0.8990  0.678189      47   \n",
       "\n",
       "    coverage  signal_coverage_ratio  \n",
       "0        225               0.795053  \n",
       "1        172               0.929730  \n",
       "2        164               0.953488  \n",
       "3        168               0.960000  \n",
       "4        167               0.982353  \n",
       "5        184               0.934010  \n",
       "6        141               0.952703  \n",
       "7        131               0.970370  \n",
       "8        134               0.971014  \n",
       "9        131               0.984962  \n",
       "10       139               0.868750  \n",
       "11        32               0.864865  \n",
       "12        38               0.950000  \n",
       "13        34               0.971429  \n",
       "14        59               0.951613  \n",
       "15        26               0.962963  \n",
       "16        22               1.000000  \n",
       "17        48               0.979592  \n",
       "18        25               1.000000  \n",
       "19        52               1.000000  \n",
       "20        46               0.978723  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_mutex(x_df_mets_3, pairs, permutations=2000,saving_file ='mutex_mets_cnv_3' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR\n",
      "TP53\n",
      "0.0595 0.97\n",
      "AR\n",
      "MDM4\n",
      "0.304 0.78\n",
      "AR\n",
      "CDK4\n",
      "0.6535 0.459\n",
      "AR\n",
      "CDK6\n",
      "0.7555 0.3345\n",
      "AR\n",
      "CDKN2A\n",
      "0.3035 0.822\n",
      "AR\n",
      "RB1\n",
      "0.006 1.0\n",
      "TP53\n",
      "MDM4\n",
      "0.0 1.0\n",
      "TP53\n",
      "CDK4\n",
      "0.03 0.976\n",
      "TP53\n",
      "CDK6\n",
      "0.5115 0.6075\n",
      "TP53\n",
      "CDKN2A\n",
      "0.994 0.012\n",
      "TP53\n",
      "RB1\n",
      "0.762 0.345\n",
      "MDM4\n",
      "CDK4\n",
      "1.0 0.0\n",
      "MDM4\n",
      "CDK6\n",
      "0.982 0.03\n",
      "MDM4\n",
      "CDKN2A\n",
      "0.649 0.4755\n",
      "MDM4\n",
      "RB1\n",
      "0.1245 0.9465\n",
      "CDK4\n",
      "CDK6\n",
      "0.8935 0.1485\n",
      "CDK4\n",
      "CDKN2A\n",
      "0.845 0.232\n",
      "CDK4\n",
      "RB1\n",
      "0.006 1.0\n",
      "CDK6\n",
      "CDKN2A\n",
      "0.8335 0.2375\n",
      "CDK6\n",
      "RB1\n",
      "0.4005 0.7185\n",
      "CDKN2A\n",
      "RB1\n",
      "0.8875 0.1725\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>g1</th>\n",
       "      <th>g2</th>\n",
       "      <th>mutex_pvalue</th>\n",
       "      <th>co_occurence_pvalue</th>\n",
       "      <th>zscore</th>\n",
       "      <th>signal</th>\n",
       "      <th>coverage</th>\n",
       "      <th>signal_coverage_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AR</td>\n",
       "      <td>TP53</td>\n",
       "      <td>0.0595</td>\n",
       "      <td>0.9700</td>\n",
       "      <td>1.596703</td>\n",
       "      <td>428</td>\n",
       "      <td>282</td>\n",
       "      <td>0.658879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AR</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.3040</td>\n",
       "      <td>0.7800</td>\n",
       "      <td>0.606091</td>\n",
       "      <td>333</td>\n",
       "      <td>242</td>\n",
       "      <td>0.726727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.6535</td>\n",
       "      <td>0.4590</td>\n",
       "      <td>-0.320006</td>\n",
       "      <td>278</td>\n",
       "      <td>219</td>\n",
       "      <td>0.787770</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.7555</td>\n",
       "      <td>0.3345</td>\n",
       "      <td>-0.569941</td>\n",
       "      <td>328</td>\n",
       "      <td>236</td>\n",
       "      <td>0.719512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.3035</td>\n",
       "      <td>0.8220</td>\n",
       "      <td>0.646660</td>\n",
       "      <td>271</td>\n",
       "      <td>220</td>\n",
       "      <td>0.811808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>AR</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0060</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.101592</td>\n",
       "      <td>441</td>\n",
       "      <td>292</td>\n",
       "      <td>0.662132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>TP53</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.110388</td>\n",
       "      <td>381</td>\n",
       "      <td>276</td>\n",
       "      <td>0.724409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.0300</td>\n",
       "      <td>0.9760</td>\n",
       "      <td>2.224243</td>\n",
       "      <td>326</td>\n",
       "      <td>261</td>\n",
       "      <td>0.800613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.5115</td>\n",
       "      <td>0.6075</td>\n",
       "      <td>0.078018</td>\n",
       "      <td>376</td>\n",
       "      <td>265</td>\n",
       "      <td>0.704787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.9940</td>\n",
       "      <td>0.0120</td>\n",
       "      <td>-2.337151</td>\n",
       "      <td>319</td>\n",
       "      <td>246</td>\n",
       "      <td>0.771160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>TP53</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.7620</td>\n",
       "      <td>0.3450</td>\n",
       "      <td>-0.570170</td>\n",
       "      <td>489</td>\n",
       "      <td>289</td>\n",
       "      <td>0.591002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-2.990367</td>\n",
       "      <td>231</td>\n",
       "      <td>176</td>\n",
       "      <td>0.761905</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.9820</td>\n",
       "      <td>0.0300</td>\n",
       "      <td>-2.013451</td>\n",
       "      <td>281</td>\n",
       "      <td>205</td>\n",
       "      <td>0.729537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.6490</td>\n",
       "      <td>0.4755</td>\n",
       "      <td>-0.242026</td>\n",
       "      <td>224</td>\n",
       "      <td>182</td>\n",
       "      <td>0.812500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.1245</td>\n",
       "      <td>0.9465</td>\n",
       "      <td>1.311811</td>\n",
       "      <td>394</td>\n",
       "      <td>278</td>\n",
       "      <td>0.705584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.8935</td>\n",
       "      <td>0.1485</td>\n",
       "      <td>-1.058047</td>\n",
       "      <td>226</td>\n",
       "      <td>179</td>\n",
       "      <td>0.792035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.8450</td>\n",
       "      <td>0.2320</td>\n",
       "      <td>-0.916406</td>\n",
       "      <td>169</td>\n",
       "      <td>140</td>\n",
       "      <td>0.828402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0060</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>2.913080</td>\n",
       "      <td>339</td>\n",
       "      <td>273</td>\n",
       "      <td>0.805310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.8335</td>\n",
       "      <td>0.2375</td>\n",
       "      <td>-0.841282</td>\n",
       "      <td>219</td>\n",
       "      <td>176</td>\n",
       "      <td>0.803653</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.4005</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.412827</td>\n",
       "      <td>389</td>\n",
       "      <td>274</td>\n",
       "      <td>0.704370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.8875</td>\n",
       "      <td>0.1725</td>\n",
       "      <td>-1.161009</td>\n",
       "      <td>332</td>\n",
       "      <td>260</td>\n",
       "      <td>0.783133</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        g1      g2  mutex_pvalue  co_occurence_pvalue    zscore  signal  \\\n",
       "0       AR    TP53        0.0595               0.9700  1.596703     428   \n",
       "1       AR    MDM4        0.3040               0.7800  0.606091     333   \n",
       "2       AR    CDK4        0.6535               0.4590 -0.320006     278   \n",
       "3       AR    CDK6        0.7555               0.3345 -0.569941     328   \n",
       "4       AR  CDKN2A        0.3035               0.8220  0.646660     271   \n",
       "5       AR     RB1        0.0060               1.0000  3.101592     441   \n",
       "6     TP53    MDM4        0.0000               1.0000  3.110388     381   \n",
       "7     TP53    CDK4        0.0300               0.9760  2.224243     326   \n",
       "8     TP53    CDK6        0.5115               0.6075  0.078018     376   \n",
       "9     TP53  CDKN2A        0.9940               0.0120 -2.337151     319   \n",
       "10    TP53     RB1        0.7620               0.3450 -0.570170     489   \n",
       "11    MDM4    CDK4        1.0000               0.0000 -2.990367     231   \n",
       "12    MDM4    CDK6        0.9820               0.0300 -2.013451     281   \n",
       "13    MDM4  CDKN2A        0.6490               0.4755 -0.242026     224   \n",
       "14    MDM4     RB1        0.1245               0.9465  1.311811     394   \n",
       "15    CDK4    CDK6        0.8935               0.1485 -1.058047     226   \n",
       "16    CDK4  CDKN2A        0.8450               0.2320 -0.916406     169   \n",
       "17    CDK4     RB1        0.0060               1.0000  2.913080     339   \n",
       "18    CDK6  CDKN2A        0.8335               0.2375 -0.841282     219   \n",
       "19    CDK6     RB1        0.4005               0.7185  0.412827     389   \n",
       "20  CDKN2A     RB1        0.8875               0.1725 -1.161009     332   \n",
       "\n",
       "    coverage  signal_coverage_ratio  \n",
       "0        282               0.658879  \n",
       "1        242               0.726727  \n",
       "2        219               0.787770  \n",
       "3        236               0.719512  \n",
       "4        220               0.811808  \n",
       "5        292               0.662132  \n",
       "6        276               0.724409  \n",
       "7        261               0.800613  \n",
       "8        265               0.704787  \n",
       "9        246               0.771160  \n",
       "10       289               0.591002  \n",
       "11       176               0.761905  \n",
       "12       205               0.729537  \n",
       "13       182               0.812500  \n",
       "14       278               0.705584  \n",
       "15       179               0.792035  \n",
       "16       140               0.828402  \n",
       "17       273               0.805310  \n",
       "18       176               0.803653  \n",
       "19       274               0.704370  \n",
       "20       260               0.783133  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_mutex(x_df_mets_5, pairs, permutations=2000,saving_file ='mutex_mets_cnv_5' )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## cBio (fisher exact)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.stats import chi2_contingency\n",
    "import scipy.stats as stats\n",
    "from sklearn import metrics\n",
    "import numpy as np\n",
    "\n",
    "def compare_pair(df, g1, g2):\n",
    "    cm = metrics.confusion_matrix(df[g1], df[g2], labels=[0,1])\n",
    "    print(cm)\n",
    "    A= cm[1,1] #both\n",
    "    B= cm[1,0] # G1 not G2\n",
    "    C= cm[0,1] # G2 not G1\n",
    "    D= cm[0,0] #neither\n",
    "    OR= (A*D)/(B*C)\n",
    "    log2_OR = np.log2(OR)\n",
    "    results_dict={}\n",
    "    results_dict['G1'] = g1\n",
    "    results_dict['G2'] = g2\n",
    "    results_dict['both'] = A\n",
    "    results_dict['G1 not G2'] = B\n",
    "    results_dict['G2 not G1'] = C\n",
    "    results_dict['neither'] = D\n",
    "    results_dict['OR'] = OR\n",
    "    results_dict['log2_OR'] = log2_OR\n",
    "    \n",
    "    chi2, chi2_pvalue, dof, ex = chi2_contingency(cm)\n",
    "    results_dict['p_value_chi2'] = chi2_pvalue\n",
    "    oddsratio, p_value= stats.fisher_exact(cm)\n",
    "    results_dict['p_value_fisher'] = p_value\n",
    "#     results_dict['oddsratio'] = oddsratio\n",
    "    return results_dict\n",
    "\n",
    "def run_cbio(df, pairs, saving_file):\n",
    "    results_list =[] \n",
    "    for p in pairs:\n",
    "        g1, g2 =p\n",
    "        print (g1, g2)\n",
    "        results_dict = compare_pair(df.T, g1, g2) \n",
    "        results_list.append(results_dict)\n",
    "#         print (results_dict)\n",
    "    results_df = pd.DataFrame(results_list)\n",
    "    def label_race (row):\n",
    "        if row['OR'] >=1.  :\n",
    "            return 'Co-occurrence'\n",
    "        else:\n",
    "            return 'Mutual exclusivity'\n",
    "    \n",
    "    results_df['Tendency'] =results_df.apply (lambda row: label_race(row), axis=1)\n",
    "\n",
    "    results_df ['OR'] = results_df['OR'].map('{:,.3f}'.format)\n",
    "    results_df ['log2_OR'] = results_df['log2_OR'].map('{:,.3f}'.format)\n",
    "    results_df ['p_value_fisher'] = results_df['p_value_fisher'].map('{:,.3f}'.format)\n",
    "    results_df ['p_value_chi2'] = results_df['p_value_chi2'].map('{:,.3f}'.format)\n",
    "    \n",
    "    cols= ['G1','G2', 'neither' , 'G1 not G2', 'G2 not G1', 'both','OR',  'log2_OR', 'p_value_chi2', 'p_value_fisher','Tendency']\n",
    "    results_df = results_df.reindex(cols, axis=1)\n",
    "    results_df.to_csv('{}.csv'.format(saving_file))\n",
    "    return results_df\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR TP53\n",
      "[[ 51  92]\n",
      " [ 44 146]]\n",
      "AR MDM4\n",
      "[[91 52]\n",
      " [99 91]]\n",
      "AR CDK4\n",
      "[[114  29]\n",
      " [131  59]]\n",
      "AR CDK6\n",
      "[[97 46]\n",
      " [98 92]]\n",
      "AR CDKN2A\n",
      "[[113  30]\n",
      " [139  51]]\n",
      "AR RB1\n",
      "[[ 41 102]\n",
      " [ 41 149]]\n",
      "TP53 MDM4\n",
      "[[ 57  38]\n",
      " [133 105]]\n",
      "TP53 CDK4\n",
      "[[ 72  23]\n",
      " [173  65]]\n",
      "TP53 CDK6\n",
      "[[ 68  27]\n",
      " [127 111]]\n",
      "TP53 CDKN2A\n",
      "[[ 87   8]\n",
      " [165  73]]\n",
      "TP53 RB1\n",
      "[[ 44  51]\n",
      " [ 38 200]]\n",
      "MDM4 CDK4\n",
      "[[157  33]\n",
      " [ 88  55]]\n",
      "MDM4 CDK6\n",
      "[[128  62]\n",
      " [ 67  76]]\n",
      "MDM4 CDKN2A\n",
      "[[151  39]\n",
      " [101  42]]\n",
      "MDM4 RB1\n",
      "[[ 55 135]\n",
      " [ 27 116]]\n",
      "CDK4 CDK6\n",
      "[[154  91]\n",
      " [ 41  47]]\n",
      "CDK4 CDKN2A\n",
      "[[193  52]\n",
      " [ 59  29]]\n",
      "CDK4 RB1\n",
      "[[ 60 185]\n",
      " [ 22  66]]\n",
      "CDK6 CDKN2A\n",
      "[[157  38]\n",
      " [ 95  43]]\n",
      "CDK6 RB1\n",
      "[[ 59 136]\n",
      " [ 23 115]]\n",
      "CDKN2A RB1\n",
      "[[ 73 179]\n",
      " [  9  72]]\n"
     ]
    }
   ],
   "source": [
    "ret_df= run_cbio(x_df_mets_5, pairs,saving_file ='cbio_mets_cnv5' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR TP53\n",
      "[[108  65]\n",
      " [102  58]]\n",
      "AR MDM4\n",
      "[[161  12]\n",
      " [147  13]]\n",
      "AR CDK4\n",
      "[[169   4]\n",
      " [152   8]]\n",
      "AR CDK6\n",
      "[[165   8]\n",
      " [153   7]]\n",
      "AR CDKN2A\n",
      "[[166   7]\n",
      " [157   3]]\n",
      "AR RB1\n",
      "[[149  24]\n",
      " [147  13]]\n",
      "TP53 MDM4\n",
      "[[192  18]\n",
      " [116   7]]\n",
      "TP53 CDK4\n",
      "[[202   8]\n",
      " [119   4]]\n",
      "TP53 CDK6\n",
      "[[199  11]\n",
      " [119   4]]\n",
      "TP53 CDKN2A\n",
      "[[202   8]\n",
      " [121   2]]\n",
      "TP53 RB1\n",
      "[[194  16]\n",
      " [102  21]]\n",
      "MDM4 CDK4\n",
      "[[301   7]\n",
      " [ 20   5]]\n",
      "MDM4 CDK6\n",
      "[[295  13]\n",
      " [ 23   2]]\n",
      "MDM4 CDKN2A\n",
      "[[299   9]\n",
      " [ 24   1]]\n",
      "MDM4 RB1\n",
      "[[274  34]\n",
      " [ 22   3]]\n",
      "CDK4 CDK6\n",
      "[[307  14]\n",
      " [ 11   1]]\n",
      "CDK4 CDKN2A\n",
      "[[311  10]\n",
      " [ 12   0]]\n",
      "CDK4 RB1\n",
      "[[285  36]\n",
      " [ 11   1]]\n",
      "CDK6 CDKN2A\n",
      "[[308  10]\n",
      " [ 15   0]]\n",
      "CDK6 RB1\n",
      "[[281  37]\n",
      " [ 15   0]]\n",
      "CDKN2A RB1\n",
      "[[287  36]\n",
      " [  9   1]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/haithamelmarakeby/anaconda2/envs/nlp/lib/python3.7/site-packages/ipykernel_launcher.py:14: RuntimeWarning: divide by zero encountered in log2\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "ret_df= run_cbio(x_df_mets_3, pairs,saving_file ='cbio_mets_cnv3' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR TP53\n",
      "[[696 148]\n",
      " [107  60]]\n",
      "AR MDM4\n",
      "[[821  23]\n",
      " [153  14]]\n",
      "AR CDK4\n",
      "[[830  14]\n",
      " [158   9]]\n",
      "AR CDK6\n",
      "[[820  24]\n",
      " [160   7]]\n",
      "AR CDKN2A\n",
      "[[831  13]\n",
      " [164   3]]\n",
      "AR RB1\n",
      "[[801  43]\n",
      " [154  13]]\n",
      "TP53 MDM4\n",
      "[[774  29]\n",
      " [200   8]]\n",
      "TP53 CDK4\n",
      "[[786  17]\n",
      " [202   6]]\n",
      "TP53 CDK6\n",
      "[[777  26]\n",
      " [203   5]]\n",
      "TP53 CDKN2A\n",
      "[[790  13]\n",
      " [205   3]]\n",
      "TP53 RB1\n",
      "[[774  29]\n",
      " [181  27]]\n",
      "MDM4 CDK4\n",
      "[[958  16]\n",
      " [ 30   7]]\n",
      "MDM4 CDK6\n",
      "[[946  28]\n",
      " [ 34   3]]\n",
      "MDM4 CDKN2A\n",
      "[[959  15]\n",
      " [ 36   1]]\n",
      "MDM4 RB1\n",
      "[[921  53]\n",
      " [ 34   3]]\n",
      "CDK4 CDK6\n",
      "[[960  28]\n",
      " [ 20   3]]\n",
      "CDK4 CDKN2A\n",
      "[[972  16]\n",
      " [ 23   0]]\n",
      "CDK4 RB1\n",
      "[[933  55]\n",
      " [ 22   1]]\n",
      "CDK6 CDKN2A\n",
      "[[964  16]\n",
      " [ 31   0]]\n",
      "CDK6 RB1\n",
      "[[924  56]\n",
      " [ 31   0]]\n",
      "CDKN2A RB1\n",
      "[[940  55]\n",
      " [ 15   1]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/haithamelmarakeby/anaconda2/envs/nlp/lib/python3.7/site-packages/ipykernel_launcher.py:14: RuntimeWarning: divide by zero encountered in log2\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "ret_df= run_cbio(x_df_3, pairs,saving_file ='cbio_all_cnv3' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR TP53\n",
      "[[472 342]\n",
      " [ 46 151]]\n",
      "AR MDM4\n",
      "[[706 108]\n",
      " [103  94]]\n",
      "AR CDK4\n",
      "[[735  79]\n",
      " [135  62]]\n",
      "AR CDK6\n",
      "[[631 183]\n",
      " [102  95]]\n",
      "AR CDKN2A\n",
      "[[727  87]\n",
      " [144  53]]\n",
      "AR RB1\n",
      "[[392 422]\n",
      " [ 44 153]]\n",
      "TP53 MDM4\n",
      "[[454  64]\n",
      " [355 138]]\n",
      "TP53 CDK4\n",
      "[[472  46]\n",
      " [398  95]]\n",
      "TP53 CDK6\n",
      "[[420  98]\n",
      " [313 180]]\n",
      "TP53 CDKN2A\n",
      "[[497  21]\n",
      " [374 119]]\n",
      "TP53 RB1\n",
      "[[288 230]\n",
      " [148 345]]\n",
      "MDM4 CDK4\n",
      "[[734  75]\n",
      " [136  66]]\n",
      "MDM4 CDK6\n",
      "[[639 170]\n",
      " [ 94 108]]\n",
      "MDM4 CDKN2A\n",
      "[[724  85]\n",
      " [147  55]]\n",
      "MDM4 RB1\n",
      "[[392 417]\n",
      " [ 44 158]]\n",
      "CDK4 CDK6\n",
      "[[651 219]\n",
      " [ 82  59]]\n",
      "CDK4 CDKN2A\n",
      "[[763 107]\n",
      " [108  33]]\n",
      "CDK4 RB1\n",
      "[[392 478]\n",
      " [ 44  97]]\n",
      "CDK6 CDKN2A\n",
      "[[658  75]\n",
      " [213  65]]\n",
      "CDK6 RB1\n",
      "[[367 366]\n",
      " [ 69 209]]\n",
      "CDKN2A RB1\n",
      "[[406 465]\n",
      " [ 30 110]]\n"
     ]
    }
   ],
   "source": [
    "ret_df= run_cbio(x_df_5, pairs,saving_file ='cbio_all_cnv5' )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PAN-cancer mets dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/Users/haithamelmarakeby/PycharmProjects/pnet2/_database/prostate/external_validation/Met500'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "external_dir = join(PROSTATE_DATA_PATH, 'external_validation/Met500')\n",
    "external_dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A1BG</th>\n",
       "      <th>A1CF</th>\n",
       "      <th>A2M</th>\n",
       "      <th>A2ML1</th>\n",
       "      <th>A3GALT2</th>\n",
       "      <th>A4GALT</th>\n",
       "      <th>A4GNT</th>\n",
       "      <th>AAAS</th>\n",
       "      <th>AACS</th>\n",
       "      <th>AADAC</th>\n",
       "      <th>...</th>\n",
       "      <th>ZWILCH</th>\n",
       "      <th>ZWINT</th>\n",
       "      <th>ZXDA</th>\n",
       "      <th>ZXDB</th>\n",
       "      <th>ZXDC</th>\n",
       "      <th>ZYG11A</th>\n",
       "      <th>ZYG11B</th>\n",
       "      <th>ZYX</th>\n",
       "      <th>ZZEF1</th>\n",
       "      <th>ZZZ3</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pipeline_ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>ES_5001</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5004</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5005</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1001</th>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1002</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 16576 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             A1BG  A1CF  A2M  A2ML1  A3GALT2  A4GALT  A4GNT  AAAS  AACS  \\\n",
       "Pipeline_ID                                                               \n",
       "ES_5001       NaN   NaN  NaN    NaN      NaN     NaN    NaN   NaN   NaN   \n",
       "ES_5004       NaN   NaN  NaN    NaN      NaN     NaN    NaN   NaN   NaN   \n",
       "ES_5005       NaN   NaN  NaN    NaN      NaN     NaN    NaN   NaN   NaN   \n",
       "MO_1001       1.0   NaN  NaN    NaN      NaN     NaN    NaN   NaN   NaN   \n",
       "MO_1002       NaN   NaN  NaN    NaN      NaN     NaN    NaN   NaN   NaN   \n",
       "\n",
       "             AADAC  ...  ZWILCH  ZWINT  ZXDA  ZXDB  ZXDC  ZYG11A  ZYG11B  ZYX  \\\n",
       "Pipeline_ID         ...                                                         \n",
       "ES_5001        NaN  ...     NaN    NaN   NaN   NaN   NaN     NaN     NaN  NaN   \n",
       "ES_5004        NaN  ...     NaN    NaN   NaN   NaN   NaN     NaN     NaN  NaN   \n",
       "ES_5005        NaN  ...     NaN    NaN   NaN   NaN   NaN     NaN     NaN  NaN   \n",
       "MO_1001        NaN  ...     NaN    NaN   NaN   NaN   NaN     NaN     NaN  NaN   \n",
       "MO_1002        NaN  ...     NaN    NaN   NaN   NaN   NaN     NaN     NaN  NaN   \n",
       "\n",
       "             ZZEF1  ZZZ3  \n",
       "Pipeline_ID               \n",
       "ES_5001        NaN   NaN  \n",
       "ES_5004        NaN   NaN  \n",
       "ES_5005        NaN   NaN  \n",
       "MO_1001        NaN   NaN  \n",
       "MO_1002        1.0   NaN  \n",
       "\n",
       "[5 rows x 16576 columns]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mut_df_ext = pd.read_csv(join(external_dir, 'Met500_mut_matrix.csv'), index_col=0)\n",
    "mut_df_ext.index = mut_df_ext.index.str.split('.', 1).str[0]\n",
    "mut_df_ext.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(500, 16576)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mut_df_ext.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>AR</th>\n",
       "      <th>TP53</th>\n",
       "      <th>MDM4</th>\n",
       "      <th>CDK4</th>\n",
       "      <th>CDK6</th>\n",
       "      <th>CDKN2A</th>\n",
       "      <th>RB1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pipeline_ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>ES_5001</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5004</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5005</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1001</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1002</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              AR  TP53  MDM4  CDK4  CDK6  CDKN2A  RB1\n",
       "Pipeline_ID                                          \n",
       "ES_5001      0.0   1.0   0.0   0.0   0.0     0.0  0.0\n",
       "ES_5004      0.0   1.0   0.0   0.0   0.0     0.0  0.0\n",
       "ES_5005      0.0   1.0   0.0   0.0   0.0     0.0  0.0\n",
       "MO_1001      0.0   1.0   0.0   0.0   0.0     0.0  0.0\n",
       "MO_1002      0.0   0.0   0.0   0.0   0.0     0.0  0.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mut_df_ext_selected = mut_df_ext.loc[:, selected_genes].copy()\n",
    "mut_df_ext_selected.fillna(0, inplace=True)\n",
    "mut_df_ext_selected.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ES_5001</th>\n",
       "      <th>ES_5004</th>\n",
       "      <th>ES_5005</th>\n",
       "      <th>MO_1001</th>\n",
       "      <th>MO_1002</th>\n",
       "      <th>MO_1005</th>\n",
       "      <th>MO_1007</th>\n",
       "      <th>MO_1008</th>\n",
       "      <th>MO_1011</th>\n",
       "      <th>MO_1012</th>\n",
       "      <th>...</th>\n",
       "      <th>TP_2109</th>\n",
       "      <th>TP_2118</th>\n",
       "      <th>TP_2119</th>\n",
       "      <th>TP_2120</th>\n",
       "      <th>TP_2122</th>\n",
       "      <th>TP_2123</th>\n",
       "      <th>TP_2130</th>\n",
       "      <th>TP_2131</th>\n",
       "      <th>TP_2141</th>\n",
       "      <th>TP_2156</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gene</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>UBE2Q1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RNF14</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UBE2Q2</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RNF10</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RNF11</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 500 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ES_5001  ES_5004  ES_5005  MO_1001  MO_1002  MO_1005  MO_1007  \\\n",
       "gene                                                                    \n",
       "UBE2Q1      1.0      1.0      1.0      1.0      1.0      0.0      0.0   \n",
       "RNF14       0.0      1.0      0.0      1.0      1.0      0.0      1.0   \n",
       "UBE2Q2      0.0      0.0      0.0      1.0      1.0      0.0      1.0   \n",
       "RNF10       0.0      0.0      0.0      1.0      0.0      0.0      0.0   \n",
       "RNF11       0.0      0.0      1.0      1.0      0.0      0.0      0.0   \n",
       "\n",
       "        MO_1008  MO_1011  MO_1012  ...  TP_2109  TP_2118  TP_2119  TP_2120  \\\n",
       "gene                               ...                                       \n",
       "UBE2Q1      0.0      0.0      1.0  ...      1.0      1.0      1.0      1.0   \n",
       "RNF14       0.0      0.0      1.0  ...      0.0      0.0      1.0      1.0   \n",
       "UBE2Q2      0.0     -1.0      1.0  ...      0.0      0.0      1.0      0.0   \n",
       "RNF10       0.0     -1.0      1.0  ...     -1.0      0.0      0.0      0.0   \n",
       "RNF11       0.0      0.0      1.0  ...      0.0      0.0      0.0      1.0   \n",
       "\n",
       "        TP_2122  TP_2123  TP_2130  TP_2131  TP_2141  TP_2156  \n",
       "gene                                                          \n",
       "UBE2Q1      1.0      0.0      2.0      1.0      0.0      1.0  \n",
       "RNF14       1.0      0.0      1.0      0.0      0.0      1.0  \n",
       "UBE2Q2      1.0      1.0      1.0      0.0      0.0      1.0  \n",
       "RNF10       1.0      0.0      1.0      0.0      1.0      1.0  \n",
       "RNF11       1.0      0.0      1.0      0.0      0.0      1.0  \n",
       "\n",
       "[5 rows x 500 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cnv_df_ext = pd.read_csv(join(external_dir, 'Met500_cnv.txt'), sep='\\t', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>gene</th>\n",
       "      <th>AR</th>\n",
       "      <th>TP53</th>\n",
       "      <th>MDM4</th>\n",
       "      <th>CDK4</th>\n",
       "      <th>CDK6</th>\n",
       "      <th>CDKN2A</th>\n",
       "      <th>RB1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>ES_5001</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5004</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5005</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1001</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1002</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "gene      AR  TP53  MDM4  CDK4  CDK6  CDKN2A  RB1\n",
       "ES_5001  0.0   0.0   0.0   0.0   0.0     0.0  0.0\n",
       "ES_5004  0.0   0.0   0.0   0.0   0.0     0.0  0.0\n",
       "ES_5005  0.0   0.0   0.0   0.0   0.0     0.0  0.0\n",
       "MO_1001  0.0   0.0   0.0   0.0   0.0     0.0  0.0\n",
       "MO_1002  0.0   0.0   0.0   0.0   1.0     0.0  0.0"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cnv_df_ext_selected = cnv_df_ext.T.loc[:, selected_genes].copy()\n",
    "\n",
    "cnv_df_ext_selected = cnv_df_ext_selected.replace({-1.0: 0., -2.0:1.0, 1.0: 0., 2.0:1.})\n",
    "cnv_df_ext_selected.fillna(0.0, inplace=True)\n",
    "cnv_df_ext_selected.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0    465\n",
       "1.0     35\n",
       "Name: MDM4, dtype: int64"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cnv_df_ext_selected.MDM4.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "met500_data = pd.concat([mut_df_ext_selected, cnv_df_ext_selected], keys=['mut', 'cnv'], join='inner', axis=1 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"7\" halign=\"left\">mut</th>\n",
       "      <th colspan=\"7\" halign=\"left\">cnv</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>AR</th>\n",
       "      <th>TP53</th>\n",
       "      <th>MDM4</th>\n",
       "      <th>CDK4</th>\n",
       "      <th>CDK6</th>\n",
       "      <th>CDKN2A</th>\n",
       "      <th>RB1</th>\n",
       "      <th>AR</th>\n",
       "      <th>TP53</th>\n",
       "      <th>MDM4</th>\n",
       "      <th>CDK4</th>\n",
       "      <th>CDK6</th>\n",
       "      <th>CDKN2A</th>\n",
       "      <th>RB1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>ES_5001</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5004</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ES_5005</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1001</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO_1002</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         mut                                  cnv                             \\\n",
       "          AR TP53 MDM4 CDK4 CDK6 CDKN2A  RB1   AR TP53 MDM4 CDK4 CDK6 CDKN2A   \n",
       "ES_5001  0.0  1.0  0.0  0.0  0.0    0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.0   \n",
       "ES_5004  0.0  1.0  0.0  0.0  0.0    0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.0   \n",
       "ES_5005  0.0  1.0  0.0  0.0  0.0    0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.0   \n",
       "MO_1001  0.0  1.0  0.0  0.0  0.0    0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.0   \n",
       "MO_1002  0.0  0.0  0.0  0.0  0.0    0.0  0.0  0.0  0.0  0.0  0.0  1.0    0.0   \n",
       "\n",
       "              \n",
       "         RB1  \n",
       "ES_5001  0.0  \n",
       "ES_5004  0.0  \n",
       "ES_5005  0.0  \n",
       "MO_1001  0.0  \n",
       "MO_1002  0.0  "
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "met500_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>level_0</th>\n",
       "      <th>level_1</th>\n",
       "      <th>ES_5001</th>\n",
       "      <th>ES_5004</th>\n",
       "      <th>ES_5005</th>\n",
       "      <th>MO_1001</th>\n",
       "      <th>MO_1002</th>\n",
       "      <th>MO_1005</th>\n",
       "      <th>MO_1007</th>\n",
       "      <th>MO_1008</th>\n",
       "      <th>...</th>\n",
       "      <th>TP_2109</th>\n",
       "      <th>TP_2118</th>\n",
       "      <th>TP_2119</th>\n",
       "      <th>TP_2120</th>\n",
       "      <th>TP_2122</th>\n",
       "      <th>TP_2123</th>\n",
       "      <th>TP_2130</th>\n",
       "      <th>TP_2131</th>\n",
       "      <th>TP_2141</th>\n",
       "      <th>TP_2156</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>mut</td>\n",
       "      <td>AR</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>mut</td>\n",
       "      <td>TP53</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>mut</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>mut</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>mut</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 502 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  level_0 level_1  ES_5001  ES_5004  ES_5005  MO_1001  MO_1002  MO_1005  \\\n",
       "0     mut      AR      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "1     mut    TP53      1.0      1.0      1.0      1.0      0.0      0.0   \n",
       "2     mut    MDM4      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "3     mut    CDK4      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "4     mut    CDK6      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "\n",
       "   MO_1007  MO_1008  ...  TP_2109  TP_2118  TP_2119  TP_2120  TP_2122  \\\n",
       "0      0.0      0.0  ...      0.0      0.0      0.0      0.0      0.0   \n",
       "1      1.0      0.0  ...      0.0      1.0      0.0      1.0      4.0   \n",
       "2      0.0      0.0  ...      0.0      0.0      0.0      0.0      0.0   \n",
       "3      0.0      0.0  ...      0.0      0.0      0.0      0.0      0.0   \n",
       "4      0.0      0.0  ...      0.0      0.0      0.0      0.0      0.0   \n",
       "\n",
       "   TP_2123  TP_2130  TP_2131  TP_2141  TP_2156  \n",
       "0      0.0      0.0      0.0      0.0      0.0  \n",
       "1      0.0      2.0      0.0      1.0      1.0  \n",
       "2      0.0      0.0      0.0      0.0      0.0  \n",
       "3      0.0      0.0      0.0      0.0      0.0  \n",
       "4      0.0      0.0      0.0      0.0      0.0  \n",
       "\n",
       "[5 rows x 502 columns]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "met500_data.T.reset_index().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(7, 500)"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "met500_df_3 = met500_data.T.reset_index().groupby('level_1').sum() # all events (OR)\n",
    "met500_df_3[met500_df_3>0] = 1 # binarize \n",
    "met500_df_3.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ES_5001</th>\n",
       "      <th>ES_5004</th>\n",
       "      <th>ES_5005</th>\n",
       "      <th>MO_1001</th>\n",
       "      <th>MO_1002</th>\n",
       "      <th>MO_1005</th>\n",
       "      <th>MO_1007</th>\n",
       "      <th>MO_1008</th>\n",
       "      <th>MO_1011</th>\n",
       "      <th>MO_1012</th>\n",
       "      <th>...</th>\n",
       "      <th>TP_2109</th>\n",
       "      <th>TP_2118</th>\n",
       "      <th>TP_2119</th>\n",
       "      <th>TP_2120</th>\n",
       "      <th>TP_2122</th>\n",
       "      <th>TP_2123</th>\n",
       "      <th>TP_2130</th>\n",
       "      <th>TP_2131</th>\n",
       "      <th>TP_2141</th>\n",
       "      <th>TP_2156</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>level_1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AR</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK6</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDKN2A</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MDM4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RB1</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TP53</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7 rows × 500 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         ES_5001  ES_5004  ES_5005  MO_1001  MO_1002  MO_1005  MO_1007  \\\n",
       "level_1                                                                  \n",
       "AR           0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "CDK4         0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "CDK6         0.0      0.0      0.0      0.0      1.0      0.0      1.0   \n",
       "CDKN2A       0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "MDM4         0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "RB1          0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "TP53         1.0      1.0      1.0      1.0      0.0      0.0      1.0   \n",
       "\n",
       "         MO_1008  MO_1011  MO_1012  ...  TP_2109  TP_2118  TP_2119  TP_2120  \\\n",
       "level_1                             ...                                       \n",
       "AR           0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "CDK4         0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "CDK6         0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "CDKN2A       0.0      0.0      1.0  ...      0.0      1.0      1.0      1.0   \n",
       "MDM4         0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "RB1          0.0      0.0      1.0  ...      0.0      0.0      0.0      0.0   \n",
       "TP53         0.0      0.0      0.0  ...      0.0      1.0      0.0      1.0   \n",
       "\n",
       "         TP_2122  TP_2123  TP_2130  TP_2131  TP_2141  TP_2156  \n",
       "level_1                                                        \n",
       "AR           0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDK4         0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDK6         0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDKN2A       1.0      0.0      0.0      1.0      0.0      0.0  \n",
       "MDM4         0.0      0.0      1.0      0.0      0.0      0.0  \n",
       "RB1          0.0      0.0      0.0      0.0      1.0      1.0  \n",
       "TP53         1.0      0.0      1.0      0.0      1.0      1.0  \n",
       "\n",
       "[7 rows x 500 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "met500_df_3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR TP53\n",
      "[[225 223]\n",
      " [ 25  27]]\n",
      "AR MDM4\n",
      "[[416  32]\n",
      " [ 46   6]]\n",
      "AR CDK4\n",
      "[[438  10]\n",
      " [ 51   1]]\n",
      "AR CDK6\n",
      "[[431  17]\n",
      " [ 46   6]]\n",
      "AR CDKN2A\n",
      "[[371  77]\n",
      " [ 44   8]]\n",
      "AR RB1\n",
      "[[412  36]\n",
      " [ 47   5]]\n",
      "TP53 MDM4\n",
      "[[235  15]\n",
      " [227  23]]\n",
      "TP53 CDK4\n",
      "[[246   4]\n",
      " [243   7]]\n",
      "TP53 CDK6\n",
      "[[244   6]\n",
      " [233  17]]\n",
      "TP53 CDKN2A\n",
      "[[216  34]\n",
      " [199  51]]\n",
      "TP53 RB1\n",
      "[[245   5]\n",
      " [214  36]]\n",
      "MDM4 CDK4\n",
      "[[453   9]\n",
      " [ 36   2]]\n",
      "MDM4 CDK6\n",
      "[[447  15]\n",
      " [ 30   8]]\n",
      "MDM4 CDKN2A\n",
      "[[382  80]\n",
      " [ 33   5]]\n",
      "MDM4 RB1\n",
      "[[425  37]\n",
      " [ 34   4]]\n",
      "CDK4 CDK6\n",
      "[[468  21]\n",
      " [  9   2]]\n",
      "CDK4 CDKN2A\n",
      "[[407  82]\n",
      " [  8   3]]\n",
      "CDK4 RB1\n",
      "[[452  37]\n",
      " [  7   4]]\n",
      "CDK6 CDKN2A\n",
      "[[399  78]\n",
      " [ 16   7]]\n",
      "CDK6 RB1\n",
      "[[439  38]\n",
      " [ 20   3]]\n",
      "CDKN2A RB1\n",
      "[[376  39]\n",
      " [ 83   2]]\n"
     ]
    }
   ],
   "source": [
    "ret_df= run_cbio(met500_df_3, pairs,saving_file ='met500_cbio_mets_cnv3' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AR\n",
      "TP53\n",
      "0.0 1.0\n",
      "AR\n",
      "MDM4\n",
      "0.3555 0.804\n",
      "AR\n",
      "CDK4\n",
      "0.326 0.9345\n",
      "AR\n",
      "CDK6\n",
      "0.8445 0.321\n",
      "AR\n",
      "CDKN2A\n",
      "0.0 1.0\n",
      "AR\n",
      "RB1\n",
      "0.1435 0.9465\n",
      "TP53\n",
      "MDM4\n",
      "0.0 1.0\n",
      "TP53\n",
      "CDK4\n",
      "0.138 0.952\n",
      "TP53\n",
      "CDK6\n",
      "0.233 0.88\n",
      "TP53\n",
      "CDKN2A\n",
      "0.0 1.0\n",
      "TP53\n",
      "RB1\n",
      "0.911 0.191\n",
      "MDM4\n",
      "CDK4\n",
      "0.8045 0.54\n",
      "MDM4\n",
      "CDK6\n",
      "1.0 0.0\n",
      "MDM4\n",
      "CDKN2A\n",
      "0.0055 1.0\n",
      "MDM4\n",
      "RB1\n",
      "0.2145 0.892\n",
      "CDK4\n",
      "CDK6\n",
      "0.9475 0.225\n",
      "CDK4\n",
      "CDKN2A\n",
      "0.53 0.709\n",
      "CDK4\n",
      "RB1\n",
      "0.9705 0.0765\n",
      "CDK6\n",
      "CDKN2A\n",
      "0.5695 0.596\n",
      "CDK6\n",
      "RB1\n",
      "0.5485 0.732\n",
      "CDKN2A\n",
      "RB1\n",
      "0.0 1.0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>g1</th>\n",
       "      <th>g2</th>\n",
       "      <th>mutex_pvalue</th>\n",
       "      <th>co_occurence_pvalue</th>\n",
       "      <th>zscore</th>\n",
       "      <th>signal</th>\n",
       "      <th>coverage</th>\n",
       "      <th>signal_coverage_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AR</td>\n",
       "      <td>TP53</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>5.350893</td>\n",
       "      <td>302</td>\n",
       "      <td>275</td>\n",
       "      <td>0.910596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AR</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.3555</td>\n",
       "      <td>0.8040</td>\n",
       "      <td>0.644699</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>0.933333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.3260</td>\n",
       "      <td>0.9345</td>\n",
       "      <td>0.910256</td>\n",
       "      <td>63</td>\n",
       "      <td>62</td>\n",
       "      <td>0.984127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.8445</td>\n",
       "      <td>0.3210</td>\n",
       "      <td>-0.804866</td>\n",
       "      <td>75</td>\n",
       "      <td>69</td>\n",
       "      <td>0.920000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AR</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>2.558734</td>\n",
       "      <td>137</td>\n",
       "      <td>129</td>\n",
       "      <td>0.941606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>AR</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.1435</td>\n",
       "      <td>0.9465</td>\n",
       "      <td>1.387068</td>\n",
       "      <td>93</td>\n",
       "      <td>88</td>\n",
       "      <td>0.946237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>TP53</td>\n",
       "      <td>MDM4</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.662521</td>\n",
       "      <td>288</td>\n",
       "      <td>265</td>\n",
       "      <td>0.920139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.1380</td>\n",
       "      <td>0.9520</td>\n",
       "      <td>1.473565</td>\n",
       "      <td>261</td>\n",
       "      <td>254</td>\n",
       "      <td>0.973180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.2330</td>\n",
       "      <td>0.8800</td>\n",
       "      <td>0.915694</td>\n",
       "      <td>273</td>\n",
       "      <td>256</td>\n",
       "      <td>0.937729</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>TP53</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>5.821476</td>\n",
       "      <td>335</td>\n",
       "      <td>284</td>\n",
       "      <td>0.847761</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>TP53</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.9110</td>\n",
       "      <td>0.1910</td>\n",
       "      <td>-1.052642</td>\n",
       "      <td>291</td>\n",
       "      <td>255</td>\n",
       "      <td>0.876289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK4</td>\n",
       "      <td>0.8045</td>\n",
       "      <td>0.5400</td>\n",
       "      <td>-0.293381</td>\n",
       "      <td>49</td>\n",
       "      <td>47</td>\n",
       "      <td>0.959184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-3.108888</td>\n",
       "      <td>61</td>\n",
       "      <td>53</td>\n",
       "      <td>0.868852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>2.565239</td>\n",
       "      <td>123</td>\n",
       "      <td>118</td>\n",
       "      <td>0.959350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>MDM4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.2145</td>\n",
       "      <td>0.8920</td>\n",
       "      <td>0.973441</td>\n",
       "      <td>79</td>\n",
       "      <td>75</td>\n",
       "      <td>0.949367</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDK6</td>\n",
       "      <td>0.9475</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>-1.197231</td>\n",
       "      <td>34</td>\n",
       "      <td>32</td>\n",
       "      <td>0.941176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.5300</td>\n",
       "      <td>0.7090</td>\n",
       "      <td>0.247589</td>\n",
       "      <td>96</td>\n",
       "      <td>93</td>\n",
       "      <td>0.968750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>CDK4</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.9705</td>\n",
       "      <td>0.0765</td>\n",
       "      <td>-1.845221</td>\n",
       "      <td>52</td>\n",
       "      <td>48</td>\n",
       "      <td>0.923077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>0.5695</td>\n",
       "      <td>0.5960</td>\n",
       "      <td>0.101310</td>\n",
       "      <td>108</td>\n",
       "      <td>101</td>\n",
       "      <td>0.935185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>CDK6</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.5485</td>\n",
       "      <td>0.7320</td>\n",
       "      <td>0.298216</td>\n",
       "      <td>64</td>\n",
       "      <td>61</td>\n",
       "      <td>0.953125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>CDKN2A</td>\n",
       "      <td>RB1</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>3.729270</td>\n",
       "      <td>126</td>\n",
       "      <td>124</td>\n",
       "      <td>0.984127</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        g1      g2  mutex_pvalue  co_occurence_pvalue    zscore  signal  \\\n",
       "0       AR    TP53        0.0000               1.0000  5.350893     302   \n",
       "1       AR    MDM4        0.3555               0.8040  0.644699      90   \n",
       "2       AR    CDK4        0.3260               0.9345  0.910256      63   \n",
       "3       AR    CDK6        0.8445               0.3210 -0.804866      75   \n",
       "4       AR  CDKN2A        0.0000               1.0000  2.558734     137   \n",
       "5       AR     RB1        0.1435               0.9465  1.387068      93   \n",
       "6     TP53    MDM4        0.0000               1.0000  3.662521     288   \n",
       "7     TP53    CDK4        0.1380               0.9520  1.473565     261   \n",
       "8     TP53    CDK6        0.2330               0.8800  0.915694     273   \n",
       "9     TP53  CDKN2A        0.0000               1.0000  5.821476     335   \n",
       "10    TP53     RB1        0.9110               0.1910 -1.052642     291   \n",
       "11    MDM4    CDK4        0.8045               0.5400 -0.293381      49   \n",
       "12    MDM4    CDK6        1.0000               0.0000 -3.108888      61   \n",
       "13    MDM4  CDKN2A        0.0055               1.0000  2.565239     123   \n",
       "14    MDM4     RB1        0.2145               0.8920  0.973441      79   \n",
       "15    CDK4    CDK6        0.9475               0.2250 -1.197231      34   \n",
       "16    CDK4  CDKN2A        0.5300               0.7090  0.247589      96   \n",
       "17    CDK4     RB1        0.9705               0.0765 -1.845221      52   \n",
       "18    CDK6  CDKN2A        0.5695               0.5960  0.101310     108   \n",
       "19    CDK6     RB1        0.5485               0.7320  0.298216      64   \n",
       "20  CDKN2A     RB1        0.0000               1.0000  3.729270     126   \n",
       "\n",
       "    coverage  signal_coverage_ratio  \n",
       "0        275               0.910596  \n",
       "1         84               0.933333  \n",
       "2         62               0.984127  \n",
       "3         69               0.920000  \n",
       "4        129               0.941606  \n",
       "5         88               0.946237  \n",
       "6        265               0.920139  \n",
       "7        254               0.973180  \n",
       "8        256               0.937729  \n",
       "9        284               0.847761  \n",
       "10       255               0.876289  \n",
       "11        47               0.959184  \n",
       "12        53               0.868852  \n",
       "13       118               0.959350  \n",
       "14        75               0.949367  \n",
       "15        32               0.941176  \n",
       "16        93               0.968750  \n",
       "17        48               0.923077  \n",
       "18       101               0.935185  \n",
       "19        61               0.953125  \n",
       "20       124               0.984127  "
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "run_mutex(met500_df_3, pairs, permutations=2000,saving_file ='met500_mutex_mets_cnv_3' )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ES_5001</th>\n",
       "      <th>ES_5004</th>\n",
       "      <th>ES_5005</th>\n",
       "      <th>MO_1001</th>\n",
       "      <th>MO_1002</th>\n",
       "      <th>MO_1005</th>\n",
       "      <th>MO_1007</th>\n",
       "      <th>MO_1008</th>\n",
       "      <th>MO_1011</th>\n",
       "      <th>MO_1012</th>\n",
       "      <th>...</th>\n",
       "      <th>TP_2109</th>\n",
       "      <th>TP_2118</th>\n",
       "      <th>TP_2119</th>\n",
       "      <th>TP_2120</th>\n",
       "      <th>TP_2122</th>\n",
       "      <th>TP_2123</th>\n",
       "      <th>TP_2130</th>\n",
       "      <th>TP_2131</th>\n",
       "      <th>TP_2141</th>\n",
       "      <th>TP_2156</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>level_1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AR</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDK6</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CDKN2A</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MDM4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 500 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         ES_5001  ES_5004  ES_5005  MO_1001  MO_1002  MO_1005  MO_1007  \\\n",
       "level_1                                                                  \n",
       "AR           0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "CDK4         0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "CDK6         0.0      0.0      0.0      0.0      1.0      0.0      1.0   \n",
       "CDKN2A       0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "MDM4         0.0      0.0      0.0      0.0      0.0      0.0      0.0   \n",
       "\n",
       "         MO_1008  MO_1011  MO_1012  ...  TP_2109  TP_2118  TP_2119  TP_2120  \\\n",
       "level_1                             ...                                       \n",
       "AR           0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "CDK4         0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "CDK6         0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "CDKN2A       0.0      0.0      1.0  ...      0.0      1.0      1.0      1.0   \n",
       "MDM4         0.0      0.0      0.0  ...      0.0      0.0      0.0      0.0   \n",
       "\n",
       "         TP_2122  TP_2123  TP_2130  TP_2131  TP_2141  TP_2156  \n",
       "level_1                                                        \n",
       "AR           0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDK4         0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDK6         0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "CDKN2A       1.0      0.0      0.0      1.0      0.0      0.0  \n",
       "MDM4         0.0      0.0      1.0      0.0      0.0      0.0  \n",
       "\n",
       "[5 rows x 500 columns]"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "met500_df_3.head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:nlp]",
   "language": "python",
   "name": "conda-env-nlp-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
